import { splitMethods, importFromOrigin } from './common.js'
import { formatComputedItem } from './formatComputed.js'

//to do 除了修改script里面的filter，还需要修改<template></template>里面的 "a | filter"

export const formatFilters = (str) => {
  if (!str) return ''
  const formattedStr = str.replace(/^filters:\s?\{([\s\S]*?)\s*?\}$/g, '$1')
  const filtersList = splitMethods(formattedStr)
  if (filtersList.length > 0) {
    importFromOrigin('computed')
  }
  return filtersList.map((item) => formatComputedItem(item.trim(), 'filters')).join('')
}
